package com.LeeCode;

import java.util.HashMap;

/**
 * 好数对的数目
 */

public class Code1512 {
    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 1, 1, 3};
        System.out.println(new Code1512().numIdenticalPairs(nums));
    }

    public int numIdenticalPairs(int[] nums) {
        int ans = 0;
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            ans += map.getOrDefault(num, 0);
            map.merge(num, 1, Integer::sum);
        }
        return ans;
    }
}
